﻿namespace Hidistro.UI.SaleSystem.CodeBehind
{
    using Hidistro.Core;
    using Hidistro.Entities.Commodities;
    using Hidistro.SaleSystem.Catalog;
    using Hidistro.UI.Common.Controls;
    using System;
    using System.Linq;
    using System.Text.RegularExpressions;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using wnxd.javascript;
    public class VProductDetails_new : VshopTemplatedWebControl
    {
        private int productId;
        private HtmlGenericControl slider, pagenavi;
        private Literal bname, pname, ptext;
        private Literal price, total;
        private Literal count;
        private HtmlGenericControl pcode;
        private HtmlInputHidden hidden_skus;
        private Literal litStock;
        private HtmlGenericControl litDescription;
        protected override void AttachChildControls()
        {
            if (!int.TryParse(this.Page.Request.QueryString["ProductId"], out this.productId)) base.GotoResourceNotFound("无法找到该商品");
            ProductBrowseInfo info = ProductBrowser.GetProductBrowseInfo(this.productId, null, null);
            if (info == null) base.GotoResourceNotFound("无法找到该商品");
            PageTitle.AddSiteNameTitle(info.Product.ProductName);
            this.slider = (HtmlGenericControl)this.FindControl("slider");
            this.pagenavi = (HtmlGenericControl)this.FindControl("pagenavi");
            this.bname = (Literal)this.FindControl("bname");
            this.pname = (Literal)this.FindControl("pname");
            this.ptext = (Literal)this.FindControl("ptext");
            this.price = (Literal)this.FindControl("price");
            this.total = (Literal)this.FindControl("total");
            this.count = (Literal)this.FindControl("count");
            this.pcode = (HtmlGenericControl)this.FindControl("pcode");
            this.hidden_skus = (HtmlInputHidden)this.FindControl("hidden_skus");
            this.litStock = (Literal)this.FindControl("litStock");
            this.litDescription = (HtmlGenericControl)this.FindControl("litDescription");
            if (!this.Page.IsPostBack)
            {
                this.slider.InnerHtml += "<li style=\"display:block\"><img width=\"100%\" src=\"" + Globals.GetImgUrl(info.Product.ImageUrl1) + "\" /></li>";
                this.pagenavi.InnerHtml += "<a href=\"javascript:void(0);\" class=\"active\">1</a>";
                if (!string.IsNullOrEmpty(info.Product.ImageUrl2))
                {
                    this.slider.InnerHtml += "<li><img width=\"100%\" src=\"" + Globals.GetImgUrl(info.Product.ImageUrl2) + "\" /></li>";
                    this.pagenavi.InnerHtml += "<a href=\"javascript:void(0);\">2</a>";
                }
                if (!string.IsNullOrEmpty(info.Product.ImageUrl3))
                {
                    this.slider.InnerHtml += "<li><img width=\"100%\" src=\"" + Globals.GetImgUrl(info.Product.ImageUrl3) + "\" /></li>";
                    this.pagenavi.InnerHtml += "<a href=\"javascript:void(0);\">3</a>";
                }
                if (!string.IsNullOrEmpty(info.Product.ImageUrl4))
                {
                    this.slider.InnerHtml += "<li><img width=\"100%\" src=\"" + Globals.GetImgUrl(info.Product.ImageUrl4) + "\" /></li>";
                    this.pagenavi.InnerHtml += "<a href=\"javascript:void(0);\">4</a>";
                }
                if (!string.IsNullOrEmpty(info.Product.ImageUrl5))
                {
                    this.slider.InnerHtml += "<li><img width=\"100%\" src=\"" + Globals.GetImgUrl(info.Product.ImageUrl5) + "\" /></li>";
                    this.pagenavi.InnerHtml += "<a href=\"javascript:void(0);\">5</a>";
                }
                this.bname.Text = info.BrandName;
                this.pname.Text = info.Product.ProductName;
                this.ptext.Text = info.Product.ProductText;
                this.price.Text = info.Product.DefaultSku.SalePrice.ToString("F0");
                this.total.Text = info.Product.MarketPrice.Value.ToString("F0");
                this.count.Text = info.Product.ShowSaleCounts.ToString();
                this.pcode.InnerText = info.Product.ProductCode;
                this.hidden_skus.Value = new json(info.Product.Skus).ToString();
                this.litStock.Text = info.Product.Stock.ToString();
                if (!string.IsNullOrWhiteSpace(info.Product.Description))
                {
                    Regex regex = new Regex("<script[^>]*?>.*?</script>", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(info.Product.MobblieDescription))
                    {
                        this.litDescription.InnerHtml = Globals.ReplaceImgUrl(regex.Replace(info.Product.MobblieDescription, ""));
                    }
                    else
                    {
                        this.litDescription.InnerHtml = Globals.ReplaceImgUrl(regex.Replace(info.Product.Description, ""));
                    }
                }
            }
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "Skin-VProductDetails_new.html";
            }
            base.OnInit(e);
        }
    }
}

